<?php
/**
 * Custom Application User class
 *
 * @author Xavier VILAIN
 */
class User extends \Fox\User
{
	/**
	 * Preference to maintain the link between a contact
	 * and a user
	 */
	const PREFERENCE_LINK_TO_CONTACT  = "customercode";

	/**
	 * Apps user's selection limits.
	 *
	 * @see Fox_User::createSelectionLimits()
	 */
	protected function createSelectionLimits() {

	}

	/**
	 * Find and return \Nawa\Customer
	 * @return \Nawa\Customer
	 */
	public function contact()
	{
		try {
			return \Fox\Dao::load(\Nawa\Customer::className(),
			$this->contactId());
		}
		catch(\Fox\Object\Exception\NotExist $e)
		{
			return new \Nawa\Customer();
		}
	}

	/**
	 * Find and Return Contact iD
	 * Contact id is store has a preference
	 * @return string
	 */
	public function contactId()
	{
		return $this->getPrefs(self::PREFERENCE_LINK_TO_CONTACT);
	}
}